package la.renzhen.rtpt.demo.controller;

import la.renzhen.rtpt.demo.configuration.DemoConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *
 * @author <a href="mailto:zhouhaichao@2008.sina.com">haiker</a>
 * @version 09/05/2018 2:52 PM
 */
@RestController
public class DemoController {

    @Autowired
    DemoConfig cfg;

    @GetMapping("/")
    public Map index() {
        Map map = new HashMap();
        map.put("name", cfg.param1());
        map.put("age", cfg.param2());
        map.put("sub", cfg.sub());
        return map;
    }

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("/lookup/{serviceId}")
    public List<ServiceInstance> lookup(@PathVariable String serviceId) {
        return discoveryClient.getInstances(serviceId);
    }
}
